package cn.enilu.guns.admin.modular.door;

import cn.enilu.guns.bean.annotion.core.Permission;
import cn.enilu.guns.bean.entity.door.EntranceGardUser;
import cn.enilu.guns.bean.entity.system.User;
import cn.enilu.guns.service.door.EntranceGardUserService;

import cn.enilu.guns.bean.annotion.core.BussinessLog;
import cn.enilu.guns.bean.constant.factory.PageFactory;
import cn.enilu.guns.bean.dictmap.CommonDict;
import cn.enilu.guns.admin.core.base.controller.BaseController;
import cn.enilu.guns.bean.exception.GunsException;

import cn.enilu.guns.bean.vo.query.Page;
import cn.enilu.guns.bean.vo.query.SearchFilter;


import cn.enilu.guns.shiro.ShiroKit;
import cn.enilu.guns.utils.BeanUtil;
import cn.enilu.guns.warpper.UserWarpper;
import com.google.common.base.Strings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/door/ENTRANCE/GARD/USER")
public class EntranceGardUserController extends BaseController {
	private  Logger logger = LoggerFactory.getLogger(getClass());
	@Autowired
	private EntranceGardUserService entranceGardUserService;

	private static String PREFIX = "/door/ENTRANCE/GARD/USER/";

	/**
	* 跳转到首页
	*/
	@RequestMapping(value="",method = RequestMethod.GET)
		public String index() {
		return PREFIX + "index.html";
	}

	/**
	* 跳转到添加页面
	*/
	@RequestMapping(value = "/add",method = RequestMethod.GET)
		public String add() {
		return PREFIX + "add.html";
	}

	/**
	* 跳转到修改页面
	*/
	@RequestMapping("/edit/{id}")
	public String edit(@PathVariable Long id, Model model) {
		EntranceGardUser entity = entranceGardUserService.get(id);
		model.addAttribute("item",entity);
		return PREFIX + "edit.html";
	}
	@RequestMapping(value = "/list",method = RequestMethod.POST)
	@ResponseBody
	public Object list(@RequestParam(required = false) String name) {
		Page<EntranceGardUser> page = new PageFactory<EntranceGardUser>().defaultPage();
		page.addFilter("name", SearchFilter.Operator.EQ,name);
		page = entranceGardUserService.queryPage(page);
		return super.packForBT(page);
	}
	/**
	* 新增门禁权限与人员关系表
	*/
	@RequestMapping(value = "/add",method = RequestMethod.POST)
	@ResponseBody
	@BussinessLog(value = "新增门禁权限与人员关系表", key = "name",dict= CommonDict.class)
	public Object add(EntranceGardUser entranceGardUser) {
		entranceGardUserService.insert(entranceGardUser);
		return SUCCESS_TIP;
	}

	/**
	* 删除门禁权限与人员关系表
	*/
	@RequestMapping(value = "/delete")
	@ResponseBody
	@BussinessLog(value = "删除门禁权限与人员关系表", key = "id",dict= CommonDict.class)
	public Object delete(@RequestParam Long id) {
		entranceGardUserService.delete(id);
		return SUCCESS_TIP;
	}

	/**
	* 修改门禁权限与人员关系表
	*/
	@RequestMapping(value = "/update")
	@ResponseBody
	@BussinessLog(value = "修改门禁权限与人员关系表", key = "name",dict= CommonDict.class)
	public Object update(EntranceGardUser entranceGardUser) {
		entranceGardUserService.update(entranceGardUser);
		return SUCCESS_TIP;
	}

}